package com.iprojectmanager.managers;
import javax.persistence.*;
import java.util.*;
import com.iprojectmanager.entities.*;

/**
 * @author Jons
 */

public class RolManager extends IProjectManager
{
    public RolManager()
    {
        super();
    }

    public ArrayList<Rol> getRoles()
    {
        EntityManager em = emf.createEntityManager();
        List roles = em.createQuery("Select x From Rol x").getResultList();
        ArrayList<Rol> rolesfound = new ArrayList<Rol>();

            for(int inx=0;inx<roles.size();inx++)
            {
                rolesfound.add((Rol)roles.get(inx));
            }

        return rolesfound;
    }

    public Rol getRoles(long id)
    {
        EntityManager em = emf.createEntityManager();
        List roles = em.createQuery("Select x From Rol x Where x.id = " + id).getResultList();
        Rol rol = (Rol)roles.get(0);
        return rol;
    }

    public Rol getRoles(String id)
    {
        EntityManager em = emf.createEntityManager();
        List roles = em.createQuery("Select x From Rol x Where x.nombre = '" + id + "'").getResultList();
        Rol rol = null;
            if(roles.size() > 0)
            {
                rol = (Rol)roles.get(0);
            }
        return rol;
    }
}